package com.huatai.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.common.api.R;
import com.huatai.user.constant.RedisConstant;
import com.huatai.user.entity.LinkInfo;
import com.huatai.user.mapper.LinkInfoMapper;
import com.huatai.user.service.LinkInfoService;
import com.huatai.user.service.ServerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class LinkInfoServiceImpl extends ServiceImpl<LinkInfoMapper, LinkInfo> implements LinkInfoService {

	@Autowired
	private ServerInfoService serverInfoService;

	@Autowired
	private StringRedisTemplate redisTemplate;

	@Override
	public Integer getLink(String serverIp) {
		Integer maxLink = serverInfoService.getMaxLinkValue(serverIp);
//		Set<String> keys = redisTemplate.keys(RedisConstant.SERVER_CONNECTION_USERS + serverIp + ":*");
//		if(maxLink > keys.size()){
//			return maxLink-keys.size();
//		}
		return maxLink;
	}
}
